package com.my.demo.shiro.redis;

import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

//自定义shiro缓存管理器

public class RedisCacheManager implements CacheManager {

  private RedisTemplate redisTemplate;

  public void setRedisTemplate(RedisTemplate redisTemplate) {
    this.redisTemplate = redisTemplate;
  }

  //参数1:认证或者是授权缓存的统一名称
  @Override
  public <K, V> Cache<K, V> getCache(String cacheName) throws CacheException {
    RedisCache redisCache = new RedisCache();
    redisCache.setRedisTemplate(redisTemplate);
    return redisCache;
  }

}

